package br.com.poc.pitagorasnumero.view.activity;

import java.util.ArrayList;

import roboguice.activity.RoboFragmentActivity;
import roboguice.inject.ContentView;
import roboguice.inject.InjectView;
import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import br.com.poc.pitagorasnumero.R;
import br.com.poc.pitagorasnumero.constant.*;
import br.com.poc.pitagorasnumero.presenter.INameDetailResultPresenter;
import br.com.poc.pitagorasnumero.view.dto.ResultPitagorasDTO;

import com.google.inject.Inject;

/**
 * The Class MainActivity.
 * 
 * @author irlan.gomes
 */
@ContentView(R.layout.name_full_activity)
public class NameFullActivity extends RoboFragmentActivity implements
		OnClickListener {

	/** The edt nome. */
	@InjectView(R.id.edt_name)
	private EditText edtNome;

	/** The btn ok. */
	@InjectView(IdViewConst.BTN_OK_NAME_FULL)
	private Button btnOk;

	/** The pitagoras presenter. */
	@Inject
	private INameDetailResultPresenter nameDetailResultPresenter;

	/*
	 * (non-Javadoc)
	 * 
	 * @see roboguice.activity.RoboActivity#onCreate(android.os.Bundle)
	 */
	@Override
	protected void onCreate(final Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setOnclick();
	}

	/**
	 * Sets the onclick.
	 */
	private void setOnclick() {
		this.btnOk.setOnClickListener(this);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.app.Activity#onResume()
	 */
	@Override
	protected void onResume() {
		super.onResume();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.view.View.OnClickListener#onClick(android.view.View)
	 */
	@Override
	public void onClick(final View view) {

		switch (view.getId()) {
		case IdViewConst.BTN_OK_NAME_FULL:

			doActionResult();

			break;

		default:
			break;
		}
	}

	/**
	 * Do action result.
	 */
	private void doActionResult() {
		final String nome = this.edtNome.getText().toString();
		final ArrayList<ResultPitagorasDTO> valorNomeComp = (ArrayList<ResultPitagorasDTO>) this.nameDetailResultPresenter
				.getResultPitagorasList(nome);
		final Bundle bundle = new Bundle();
		final Intent intent = new Intent(getApplicationContext(),
				PitagorasDetailActivity.class);

		bundle.putParcelableArrayList(TagConst.ACTION_DETAIL_NAME,
				valorNomeComp);
		intent.putExtras(bundle);
		startActivity(intent);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.app.Activity#onOptionsItemSelected(android.view.MenuItem)
	 */
	@Override
	public boolean onOptionsItemSelected(final MenuItem item) {
		return super.onOptionsItemSelected(item);
	}
}
